{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pythreejs import *\n",
    "import numpy as np\n",
    "from IPython.display import display\n",
    "from ipywidgets import HTML, Text\n",
    "from traitlets import link, dlink"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f236ed6bb07044b8a411345bc2968bfe",
       "version_major": "2",
       "version_minor": "0"
      },
      "text/plain": [
       "A Jupyter Widget"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ball = Mesh(geometry=SphereGeometry(radius=1), \n",
    "                                    material=LambertMaterial(color='red'),\n",
    "                                    position=[2, 1, 0])\n",
    "\n",
    "scene = Scene(children=[ball, AmbientLight(color='#777777')])\n",
    "\n",
    "c = PerspectiveCamera(position=[0, 5, 5], up=[0, 0, 1],\n",
    "                      children=[DirectionalLight(color='white', \n",
    "                                                 position=[3, 5, 1], \n",
    "                                                 intensity=0.5)])\n",
    "renderer = Renderer(camera=c, \n",
    "                    scene=scene, \n",
    "                    controls=[OrbitControls(controlling=c)])\n",
    "display(renderer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "ball.geometry.radius = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6e9a62c07bcc4089987fb0588ff64149",
       "version_major": "2",
       "version_minor": "0"
      },
      "text/plain": [
       "A Jupyter Widget"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# On windows, linewidth of the material has no effect\n",
    "size = 4\n",
    "linesgeom = PlainGeometry(vertices=[[0, 0, 0],\n",
    "                                    [size, 0, 0],\n",
    "                                    [0, 0, 0],\n",
    "                                    [0, size, 0],\n",
    "                                    [0, 0, 0],\n",
    "                                    [0, 0, size]],\n",
    "                          colors = ['red', 'red', 'green', 'green', 'white', 'orange'])\n",
    "lines = Line(geometry=linesgeom, \n",
    "             material=LineBasicMaterial(linewidth=5, vertexColors='VertexColors'), \n",
    "             type='LinePieces')\n",
    "scene = Scene(children=[lines, DirectionalLight(color='#ccaabb', position=[0,10,0]),AmbientLight(color='#cccccc')])\n",
    "c = PerspectiveCamera(position=[0, 10, 10])\n",
    "renderer = Renderer(camera=c, background='black', background_opacity=1, scene = scene, controls=[OrbitControls(controlling=c)])\n",
    "display(renderer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "widgets-tutorial",
   "language": "python",
   "name": "widgets-tutorial"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
